
#pragma once
#include <rviz_common/panel.hpp>
#include "rviz_custom_plugins/panels/ui_waypoint_panel.h"
#include "rviz_custom_plugins/utils/interactive_marker_thread.h"
#include <rviz_common/config.hpp>
#include <QStandardItemModel>
#include <interactive_markers/interactive_marker_server.hpp>
#include "rviz_custom_plugins/viewmodels/interactive_marker_model.h"
#include "rviz_custom_plugins/models/pose.h"


using rviz_common::Config;
using rviz_custom_plugins::utils::InteractiveMarkerThread;
using interactive_markers::InteractiveMarkerServer;
using rviz_custom_plugins::viewmodels::InteractiveMarkerModel;

using rviz_custom_plugins::models::Pose;


Q_DECLARE_METATYPE(InteractiveMarkerServer::FeedbackConstSharedPtr);


namespace rviz_custom_plugins
{


namespace panels
{


class WaypointPanel : public rviz_common::Panel
{
    Q_OBJECT

public:
    explicit WaypointPanel(QWidget *parent = nullptr);

    void load(const Config& config) override;

signals:
    void markerFeedbackReceived(InteractiveMarkerServer::FeedbackConstSharedPtr feedback);


private:

    inline static const QString ROW = "row";

    Ui::waypointPanel* ui{ nullptr };
    std::shared_ptr<InteractiveMarkerThread> markerThread;
    InteractiveMarkerModel* tableModel;

    void addButtonClicked();
    void removeButtonClicked();
    void insertButtonClicked();

    void addItem(int row, Pose pose);
    void removeItem(int row);


private slots:
	void handleMarkerFeedback(InteractiveMarkerServer::FeedbackConstSharedPtr feedback);
    void handlerMarkersReorder(int row, std::list<InteractiveMarker>& markers);
    void handleActiveStatusChanged(bool active);

    void handleProjectLoaded(QSharedPointer<QVariantMap> projectData);
    void handleProjectSaved(QSharedPointer<QVariantMap> projectData);
    void handleProjectClosed(QSharedPointer<QVariantMap> projectData);

};


}

}
